<template>
  <div class='icons-wrap'>
    <swiper ref="mySwiper" :options="swiperOptions">
      <swiper-slide v-for='(item,index) in swiperPages' :key='index'>
        <ul class='iconList'>
          <li v-for='(list,lindex) in item' :key='lindex' class='icon'>
            <router-link :to='list.toUrl' class='iconLink'>
              <img :src="list.imgUrl" alt="">
              <span class='iconTitle'>{{list.title}}</span>
            </router-link>
          </li>
        </ul>
      </swiper-slide>
      <!-- 分页器 -->
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
  export default {
    name: 'HomeIcons',
    props:['iconslist'],
    data() {
      return {
        swiperOptions:{
        	pagination:{
            el: '.swiper-pagination',
          },
          loop:true
        }
      }
    },
    computed:{
      swiperPages (){
        let pages = [];
        this.iconslist.forEach((item,index)=>{
              let pagesIndex = Math.floor(index/8);
              if(!pages[pagesIndex]){
                  pages[pagesIndex] = [];
              }
              pages[pagesIndex].push(item);
        });
        return pages;
      }
    }
  }
</script>


<style scoped="scoped">
  .icons-wrap{
    width:100%;
    height: 0;
    padding-bottom:45%;
    overflow: hidden;
  }
  .icons-wrap >>> .swiper-container{
    width:100%;
    height: 0;
    padding-bottom:45%;
    overflow: hidden;
  }
  .iconList{
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .iconList .icon{
    width:25%;
    padding:0.2rem 0;
    box-sizing: border-box;
  }
  .iconList .icon img{
    width:50%;
  }
  .iconLink{
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
  .iconTitle{
    color:#000;
    font-size:0.14rem;
    margin-top:0.05rem;
    width:100%;
    text-align:center;

    /* 超出部分显示省略号 */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
</style>
